
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>登录</title>
    <script src="js/vue.js"></script>
    <script src="js/axios-0.18.0.js"></script>

    <link rel="stylesheet" href="../css/page-health-login.css" />
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div class="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left"><i class="icon-back"></i>返回</span>
            <span class="center">登录界面</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="login">
                <form id='login-form' class="input-group">
                    <div class="input-row">
                        <label>用户名</label>
                        <input id='account' v-model="user.username" type="text" class="input-clear input" placeholder="请输入用户名">
                    </div>
                    <div class="input-row">
                        <label>密码</label>
                        <input id='password' v-model="user.password" type="password" class="input-clear input" placeholder="请输入密码">
                    </div>
                    <div class="btn yes-btn"><a @click="send()">登录</a></div>
                    <div class="btn yes-btn"><a href="health-register.html">无账号请先注册</a></div>
                    <div class="btn cancel-btn">取消</div>
<!---->
                </form>
            </div>
        </div>
    </div>
    <!-- 页面 css js -->

</body>

<script>

    new Vue({
        el:".app",
        data:{
            id:"",
            user:{
                username:"",
                password:""
            }
        },
        methods:{
            send(){
                //打开cookie携带开关
                axios.defaults.withCredentials = true;

                axios({
                    url:"http://localhost/login",
                    method: "post",
                    params:this.user,
                    headers:{
                        //Bearer token的规范是：Authorization名称的头，值为Bearer空格+具体的jwt串
                        "Authorization":"Bearer " + localStorage.getItem("token")
                    }
                }).then(resp=>{

                    let res = resp.data;
                    if(res.code === 1000){
                        //保存jwt
                        localStorage.setItem("token",res.data);
                        //访问数据成功,跳转到主页
                        this.idfun();

                    } else {
                        localStorage.setItem("token", " ");
                        alert(resp.data.msg)
                    }
                })
                ;
            },

            idfun(){
                console.log(this.user)
                axios({
                    url: "memberId",
                    method: "get",
                    params: {
                        "name":this.user.username
                    },
                    headers:{
                        //Bearer token的规范是：Authorization名称的头，值为Bearer空格+具体的jwt串
                        "Authorization":"Bearer " + localStorage.getItem("token")
                    }
                }).then(resp1=>{
                    console.log(resp1.data.data)
                            this.id = resp1.data.data;
                        window.location.href = "health-index.html";

                })
            }
        }
    });

</script>
</html>